import QtQuick 1.0
import "Util.js" as Util
import "Database.js" as Database

Item{
    id: _root

    property string consumerSecret: _Device.consumerSecret
    property string consumerKey: _Device.consumerKey

//    property string oauthToken: ""
//    property string oauthTokenSecret: ""
//    property string screenName: ""
//    property string userId: ""

    property variant datas: []


    function check(){
        var ret = false;

        if(datas === null){
            // ng
        }else if(datas.length === 0){
            // ng
        }else{
            // ok
            ret = true;
        }
        return ret;
    }

    // ロードする
    function load(){
        datas = Database.readAccountData();
    }

    function get(index){
        var ret = {};
        if(index < 0 || index >= datas.length){
            ret = {"number": "-1"
                , "token": ""
                , "token_secret": ""
                , "screen_name": ""
                , "user_id": ""};
        }else{
            ret = datas[index];
        }
        return ret;
    }

    function count(){
        return datas.length;
    }

    Component.onCompleted: {
//        var temp;

//        temp = Database.readData(Database.SETTING_KEY_ACCESS_TOKEN);
//        oauthToken = (temp === undefined) ? "" : temp;
//        temp = Database.readData(Database.SETTING_KEY_ACCESS_TOKEN_SECRET);
//        oauthTokenSecret = (temp === undefined) ? "" : temp;
//        temp = Database.readData(Database.SETTING_KEY_ACCESS_SCREEN_NAME);
//        screenName = (temp === undefined) ? "" : temp;
//        temp = Database.readData(Database.SETTING_KEY_ACCESS_USER_ID);
//        userId = (temp === undefined) ? "" : temp;

//        Util.outputDebugString("-- Loaded --")
//        Util.outputDebugString(" token:" + oauthToken);
//        Util.outputDebugString(" secret:" + oauthTokenSecret);
//        Util.outputDebugString(" screen name:" + screenName);
//        Util.outputDebugString(" user id:" + userId);
    }

    Component.onDestruction: {
//        Database.saveData(Database.SETTING_KEY_ACCESS_TOKEN, oauthToken);
//        Database.saveData(Database.SETTING_KEY_ACCESS_TOKEN_SECRET, oauthTokenSecret);
//        Database.saveData(Database.SETTING_KEY_ACCESS_SCREEN_NAME, screenName);
//        Database.saveData(Database.SETTING_KEY_ACCESS_USER_ID, userId);

//        Util.outputDebugString("-- Saved --")
//        Util.outputDebugString(" token:" + oauthToken);
//        Util.outputDebugString(" secret:" + oauthTokenSecret);
//        Util.outputDebugString(" screen name:" + screenName);
//        Util.outputDebugString(" user id:" + userId);
    }
}
